---
title: Zod Schema
sidebar:
    order: 80
description: Learn how to define and convert TypeScript-first Zod schemas to JSON schema
keywords: TypeScript, Zod schema, JSON schema, schema validation, type inference
---

[zod](https://zod.dev/) is a TypeScript-first schema validation with static type inference.

```ts
import { z } from "genaiscript/runtime"
// city array schema
const CitySchema = z.array(
    z.object({
        name: z.string(),
        population: z.number(),
        url: z.string(),
    })
)
```

The zod schemas can be used in `defSchema` to constrain the output of the tool.

```ts
// JSON schema to constrain the output of the tool.
const schema = defSchema("CITY_SCHEMA", CitySchema)
...
```
